1917C - Watering an Array - CodeForces Solution


brute force greedy

Please click on ads to support us..

C++ Code:

#include <iostream>
#include <bits/stdc++.h>
// #include "utilities.cpp"
using namespace std;
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define forn(i, x, n) for (int i = x; i < n; i++)
#define vi vector<int>
#define vpp vector<pair<int,int>>
#define vs vector<string>
#define vll vector<long long>
#define ss second
#define ff first
int row[] = {1,0,-1,0};
int col[] = {0,1,0,-1};
const int mod = 1e9 + 7;


void solve(){

    int n,k,d;
    cin>>n>>k>>d;

    vi a(n),v(k);
    forn(i,0,n) cin>>a[i];
    forn(i,0,k) cin>>v[i];

    int i = 0;
    int ans = 0;

    while(i < min(d, 3*n)){

        int same = 0;
        for(int j=0; j<n; j++){
            same += (a[j] == (j+1));
        }
        ans = max(ans, same+((d-(i+1))/2));

        int val = v[i%k];
        for(int j=0; j<val; j++) a[j]++;
        i++;
        
    }
    cout<<ans<<'\n';
}


signed main(){

    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1;
    // sieve();
    cin >> t;
    while (t--) solve();
    return 0;

}


Comments

Submit
0 Comments
More Questions

1487B - Cat Cycle
1679C - Rooks Defenders
56A - Bar
1694B - Paranoid String
35A - Shell Game
1684A - Digit Minimization
43B - Letter
1017A - The Rank
1698B - Rising Sand
235A - LCM Challenge
1075B - Taxi drivers and Lyft
1562A - The Miracle and the Sleeper
1216A - Prefixes
1490C - Sum of Cubes
868A - Bark to Unlock
873B - Balanced Substring
1401D - Maximum Distributed Tree
1716C - Robot in a Hallway
1688B - Patchouli's Magical Talisman
99A - Help Far Away Kingdom
622B - The Time
1688C - Manipulating History
1169D - Good Triple
1675B - Make It Increasing
588A - Duff and Meat
1541B - Pleasant Pairs
1626B - Minor Reduction
1680A - Minimums and Maximums
1713A - Traveling Salesman Problem
1713B - Optimal Reduction